import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

import {
  SHOW_TAB_BAR,
    SHOW_NAV_BAR,
    NAV_BAR_INFO,
    SHOW_PAY_PASSWORD_DIALOG
} from "@/store/MutationTypes";

export default new Vuex.Store({
  state: {
    tabBarState: false,
    navBarState: true,
    navBarInfo: {
        leftItem: {},
        rightItem: {}
    },
    payPassword: undefined
  },
  mutations: {
    [SHOW_TAB_BAR] (state, value) {
      state.tabBarState = value;
    },
    [SHOW_NAV_BAR] (state, value) {
      state.navBarState = value;
    },
    [NAV_BAR_INFO] (state, value) {
        state.navBarInfo.rightItem =  value.rightItem;
      setTimeout(() => {
          state.navBarInfo.leftItem = value.leftItem;
      }, 200)
    },
    [SHOW_PAY_PASSWORD_DIALOG] (state, value) {
      state.payPassword = value;
    }
  },
  actions: {
    [SHOW_TAB_BAR] ({commit}, value) {
      commit(SHOW_TAB_BAR, value);
    },
    [SHOW_NAV_BAR] ({commit}, value) {
      commit(SHOW_NAV_BAR, value);
    },
    [NAV_BAR_INFO] ({commit}, value) {
      commit(NAV_BAR_INFO, value);
    },
    [SHOW_PAY_PASSWORD_DIALOG] ({commit}, value) {
      commit(SHOW_PAY_PASSWORD_DIALOG, value)
    }
  }
})
